1. Field of the Invention
This invention relates to virtual machines in computer systems and, more particularly, to processing intercepted instructions.
2. Description of the Related Art
Virtualization has been used in computer systems for a variety of different purposes. For example, virtualization can be used to execute privileged software in a “container” to prevent the privileged software from directly accessing and/or making changes to at least some of the physical machine state without first being permitted to do so by a virtual machine manager (VMM) that controls the virtual machine. Such a container can prevent “buggy” or malicious software from causing problems on the physical machine. Additionally, virtualization can be used to permit two or more privileged programs to execute on the same physical machine concurrently. The privileged programs can be prevented from interfering with each other since access to the physical machine is controlled. Privileged programs may include operating systems, and may also include other software which expects to have full control of the hardware on which the software is executing. In another example, virtualization can be used to execute a privileged program on hardware that differs from the hardware expected by the privileged program.
Generally, virtualization of a processor or computer system may include providing one or more privileged programs with access to a virtual machine (the container mentioned above) over which the privileged program has full control, but the control of the physical machine is retained by the VMM. The virtual machine may include a processor (or processors), memory, and various peripheral devices that the privileged program expects to find in the machine on which it is executing. The virtual machine elements may be implemented by hardware that the VMM allocates to the virtual machine, at least temporarily, and/or may be emulated in software. Each privileged program (and related software in some cases, such as the applications that execute on an operating system) may be referred to herein as a guest. Virtualization may be implemented in software (e.g. the VMM mentioned above) without any specific hardware virtualization support in the physical machine on which the VMM and its virtual machines execute. However, virtualization may be simplified and/or achieve higher performance if some hardware support is provided.
Both the VMM and the guests are executed by the processor(s) included in the physical machine. Accordingly, switching between execution of the VMM and the execution of guests occurs in the processor(s) over time. Particularly, the VMM schedules a guest for execution, and a switch to executing that guest is performed. At various points in time, a switch from executing a guest to executing the VMM also occurs so that the VMM can retain control over the physical machine (e.g. when the guest attempts to access a peripheral device, when a new page of memory is to be allocated to the guest, when it is time for the VMM to schedule another guest, etc.). A switch between a guest and the VMM (in either direction) is often referred to as a “world switch”.
Intercepting certain instructions in the guest causes a world switch to the VMM. Instructions are intercepted for a variety of reasons. For example, an instruction that reads privileged processor state can be intercepted to ensure that the VMM will permit the guest to access the state (or to permit the VMM to perform the access on behalf of the guest). In some cases, the VMM changes processor state from the value that the guest established or expects, and instructions which access the state are intercepted to permit the VMM to supply the expected state instead of the changed state. An instruction that writes privileged state or other processor/system state that the VMM desires to control can be intercepted. In response to each interception, the VMM is invoked to emulate the intercepted event and provide an appropriate response.